package 动态规划;
//https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/
public class 买卖股票的最佳时机 {
    public int maxProfit(int[] prices) {
        int len = prices.length;
        int[][] dp = new int[len][2];
        dp[0][0] = 0;
        dp[0][1] = -prices[0];
        for (int i = 1 ; i < len ; i ++){
            dp[i][0] = Math.max(dp[i - 1][0] , dp[i - 1][1] + prices[i]);
            dp[i][1] = Math.max(dp[i - 1][1] , -prices[i]);
        }
        return dp[len - 1][0];
    }
}
